package com.ruijixiang.leetcode.everyday.leetcode2024.leetcode202409;

import java.util.Arrays;

public class leetcode20240912 {
    /**
     * 求出最多标记下标
     * 2*nums[i]<=nums[j]
     * @param nums
     * @return
     */
    public int maxNumOfMarketIndices(int[] nums){
        Arrays.sort(nums);
        int left=0;
        int right=nums.length/2+1;// 开区间
        while(left+1<right){
            int mid=(left+right)>>>1;
            if(check(nums,mid)){
                left=mid;
            }else{
                right=mid;
            }
        }
        return left*2;
    }

    // 需要保证左侧所有的数都是2*nums[i]<nums[nums.length-k+i]
    private boolean check(int[] nums,int k){
        for(int i=0;i<k;i++){
            if(nums[i]*2>nums[nums.length-k+i]){
                return false;
            }
        }
        return true;
    }
}
